#!/bin/sh
source /etc/profile
base_dir=$(cd "$(dirname "$0")"; pwd)
jar_file=`ls $base_dir -t| grep "^live-support.*\.jar$"`
server_name="live-support"
jvm_args="-Xmx2048M -Xms2048M -Duser.timezone=GMT+08"
launcher_daemon_out="server.out"

if [ ! -f "$jar_file" ]
then
    echo "can not found jar file , failed to start server! "
    exit 1
fi

pid=`ps -ef | grep "serverName=$server_name" | grep -v "grep" | awk '{print $2}'`

if [ "$pid" = "" ];then
    #nohup java -DserverName=$server_name -Djava.security.egd=file:/dev/./urandom $jvm_args -jar $jar_file --spring.config.location=./application.properties >"$launcher_daemon_out" 2>&1 < /dev/null  & 
     nohup java -DserverName=$server_name -Dbasedir=$base_dir -Djava.security.egd=file:/dev/./urandom $jvm_args -jar $jar_file --spring.config.location=./application.properties >"$launcher_daemon_out" 2>&1 < /dev/null  & 
else
    echo "$server_name is running"
fi
